<?php
namespace app\bancard\controller;
use think\Db;
use think\facade\Cache;
use app\common\validate\MessageValidate;
use app\bancard\model\Message as MessageModel;
class Message extends Common {
	
	public function index(){
		
		if (request()->isPost()) {
			$type = request()->param('type');
			$ntitle =request()->param('keywords');
			$title = isset($ntitle)?$ntitle:'';
			$limit = request()->param('limit');
			$offset = request()->param('offset');
			$start = ($offset-1)*$limit;
			$map =[
			    'school_id' => session('schoolInfo.id')
			];
			if ($title) {
			    $count = db('message')->where($map)->whereLike('content', "%$title%")->count();
			    $result = db('message')->where($map)->whereLike('content', "%$title%")->limit($start, $limit)->order('id desc')->select();
			} else {
			    $count = db('message')->where($map)->count();
			    $result = db('message')->where($map)->limit($start, $limit)->order('id desc')->select();
			}
			return showTable(0, 'OK', $count, $result, 200);
		}
		
		
		return $this->fetch();
	}
}